package frontend.registration.controller;

import java.util.Map;

import core.address.model.BasicAddress;
import core.profile.model.BasicCredential;
import core.profile.model.BasicProfile;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import frontend.registration.dao.RegisterDao;

public class RegisterAction extends ActionSupport {

private static final long serialVersionUID = 908606616890788894L;

private String emailId, password, firstname, lastname, reminderemail,conformPassword,mobile;
private BasicProfile basicProfile;
private BasicCredential basicCredential;
private BasicAddress basicAddress;

public BasicAddress getBasicAddress() {
	return basicAddress;
}

public void setBasicAddress(BasicAddress basicAddress) {
	this.basicAddress = basicAddress;
}

public BasicProfile getBasicProfile() {
	return basicProfile;
}

public void setBasicProfile(BasicProfile basicProfile) {
	this.basicProfile = basicProfile;
}

public BasicCredential getBasicCredential() {
	return basicCredential;
}

public void setBasicCredential(BasicCredential basicCredential) {
	this.basicCredential = basicCredential;
}

public String getEmailId() {
	return emailId;
}

public void setEmailId(String emailId) {
	this.emailId = emailId;
}

public String getReminderemail() {
	return reminderemail;
}

public void setReminderemail(String emailId) {
	this.reminderemail = emailId;
}

public String getPassword() {
	return password;
}

public void setPassword(String password) {
	this.password = password;
}

public String getConformPassword() {
	return conformPassword;
}

public String getFirstname() {
	return firstname;
}

public void setFirstname(String firstname) {
	this.firstname = firstname;
}

public String getLastname() {
	return lastname;
}

public void setLastname(String lastname) {
	this.lastname = lastname;
}

public String getMobile() {
	return mobile;
}

public void setMobile(String mobile) {
	this.mobile = mobile;
}

public void setConformPassword(String conformPassword) {
	this.conformPassword = conformPassword;
}

public String execute() throws Exception {
	
	if(conformPassword.equals(basicCredential.getPassword())){		
		this.basicAddress.setEmail(this.getBasicProfile().getEmailId());
		this.basicCredential.setUserId(this.getBasicProfile().getEmailId());
		this.basicCredential.setBasicprofile(this.getBasicProfile());
		this.basicCredential.setPassword(Encript.doEncript(this.getBasicCredential().getPassword()));
	if (RegisterDao.registerUser(basicCredential,basicProfile,basicAddress)){
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.put("emailId", emailId);
		session.put("logined","true");
		session.put("uuid",basicProfile.getUuid());
		
			return "success";
		}
			else
			return "fail";

	}
	else{
		return "error";
	}
}
	

}